/*-------------------------------------------------------------------------
***************** Modification History ***********************************
   @doc
   @module Multiling.c - Multi lingual support modulefunctions |
   @end
   
$Log: /SoftPay/SPK2SIM/Source/Ui/multilng.c $ 
 * 
 * 10    3/24/00 12:13p Vipin_k1
 * Code cleaned up, removed unwanted functions
 * 
 * 9     3/21/00 4:26p Jim_b4
 * 
 * 8     3/18/00 11:18p Vipin_k1
 * Added the generic logo display function inDisplayCustLogo () for the
 * custom operations
 * 
 * 7     3/16/00 6:34p Jim_b4
 * Code security functionality added
 * 
 * 6     3/14/00 7:57a Vipin_k1
 * Display data string related functions added
 * 
 * 5     3/11/00 8:11p Vipin_k1
 * Added the inMLDisplayAt() function for generic multi lingual display
 * usage
 * 
 * 4     3/06/00 7:47a Vipin_k1
 * Include file directory changes
 * 
 * 3     11/13/99 3:30a Vipin_k1
 * Added multi lingual parsing routines.
 * 
 * 3     11/05/99 10:46a Vipin_k1 
 *  Added function headers
 * 2     11/04/99 21:00a Vipin_k1
 *  Headers added
 * 1     11/04/99 11:32a Vipin_k1
 *  Created
**************************************************************************

   Copyright (C) 1999 by VeriFone, Inc.

   All rights reserved.  No part of this software may be reproduced,
   transmitted, transcribed, stored in a retrieval system, or translated
   into any language or computer language, in any form or by any means,
   electronic, mechanical, magnetic, optical, chemical, manual or otherwise,
   without the prior written permission of VeriFone, Inc.

---------------------------------------------------------------------------*/
#include <string.h>
#include <acldev.h>
#include <svc.h>
#include <svctxo.h>
#include <aclconio.h>
#include <string.h>

#include <define.h>
#include <sizes.h>
#include <multilng.h>
#include <lct.h>
#include <tblutil.h>
#include <tct.h>
#include <confio.h>
#include <ui.h>
#include <codesec.h>


#define VSMULTILNG_C

extern int inImamLineNumber;
/*-----------------------------------------------------------------------------
* Routine Name  :   int inMLDisplayAt (int inX, int inY, char *pszMsg, 
                :   int inClearOption, int inLangIndex, int inFontSize,
                :   char *pszFontName);
* Description   :   Displays the message based on the language required.
* Parameters    :   inX                     X cordinate
                    inY                     Y cordinate
                    pszMsg                  Message to be displayed
                    inClearOption           The clear options like
                                                CLR_EOL
                                                CLR_LINE
                                                NO_CLEAR
                    inLangIndex             The index of the language in the LCT
                                            The other values are:
                                                ML_USE_DEFAULT_LANG
                                                ML_USE_CURRENT_LANG
                    inFontSize              The type of the font to be used
                                            The values can be 
                                                ML_MENU_FONT
                                                ML_ACTION_FONT
                :   pszFontName             Valid only if the font to be used is not part of LCT
                                                ML_NULL_FONT if inactive
* Returns       :                           In the case of success, returns 
                                                ML_SUCCESS
                                            In case of errors, returns:
                                                ML_ERR_UNABLE_TO_SET_FONT
                                                ML_ERR_INVALID_FONT_NAME
                                                ML_ERR_LCT_ERROR
                                                ML_ERR_UNABLE_TO_RESET_FONT
                                                ML_ERR_INVALID_MESSAGE
* Notes        : 
* Modification History :
* #     Date     Who                     Description
* ----- -------- --------------------------------------------------------------
*------------------------------------------------------------------------------
*/

int inMLDisplayAt(int inX,int inY,char* pszMsg,int inClearOption,int inLangIndex,int inFontSize,char* pszFontName) {
    int inPrevXL,
    inPrevYL,
    inPrevXR,
    inPrevYR;
    int inCurXL,
    inCurYL,
    inCurXR,
    inCurYR,
    inTotalLangs;
    char szPrevFontName[FILENAME_SIZE + 1];
    char szMessage[MESSAGE_SIZE + 1];

    char szFont[FILENAME_SIZE + 1];
    //   LCT_REC srLCTLocalRec;
    unsigned char ucLCTLocalRec[SIZE_LCT_REC];

    if ((strlen(pszMsg)) > (sizeof(szMessage) - 1))
        return (ML_ERR_INVALID_MESSAGE);
    strcpy(szMessage, pszMsg);

    wherewin(&inPrevXL, &inPrevYL, &inPrevXR, &inPrevYR);
    memset(szPrevFontName, 0x00, sizeof(szPrevFontName));
    get_font(szPrevFontName);

    switch (inLangIndex) {
    case ML_USE_GIVEN_FONT:
        if (strlen(pszFontName) > sizeof(szPrevFontName) - 1)
            return (ML_ERR_INVALID_FONT_NAME);
        strcpy(szFont, pszFontName);
        if (set_font(szFont) != ML_SUCCESS)
            return (ML_ERR_UNABLE_TO_SET_FONT);
        break;
    case ML_USE_CURRENT_LANG:
        break;
    default:
        inTotalLangs = inGetLCTTotRecs();
        if (inLangIndex > (inTotalLangs - 1))
            inLangIndex = ML_USE_DEFAULT_LANG;


        if (inLoadLCTRecFromStruct(inLangIndex, ucLCTLocalRec) != VS_SUCCESS)
            return(ML_ERR_LCT_ERROR);

        if (inFontSize == ML_MENU_FONT)
            strlcpy(szFont, szGetMenuFontNameFromStruct(ucLCTLocalRec), (FILENAME_SIZE + 1));
        else
            strlcpy(szFont, szGetActionFontNameFromStruct(ucLCTLocalRec), (FILENAME_SIZE + 1));

        if (set_font(szFont) != ML_SUCCESS)
            return (ML_ERR_UNABLE_TO_SET_FONT);
        break;
    }

    wherewin(&inCurXL, &inCurYL, &inCurXR, &inCurYR);

    if ((inX < inCurXL) || (inX > inCurXR))
        inX = inCurXL;
    if (inY < inCurYL)
        inY = inCurYL; 
    if (inY > inCurYR)
        inY = inCurYR;

    vdDisplayAt(inX, inY, pszMsg, inClearOption);

    // Resetting the display attributes to the previous values
    if (set_font(szPrevFontName) != ML_SUCCESS)
        return (ML_ERR_UNABLE_TO_RESET_FONT);
    window(inPrevXL, inPrevYL, inPrevXR, inPrevYR);

    return (ML_SUCCESS);
}


/*-------------------------------------------------------------------------
    Function :    void vdDisplayDataStr(char *, int, int, int)
    Description : Displays a string right justified
    Parameters :
    Returns :
    Globals :
    Notes :
    Modification History :
      #     Date      Who                     Description
    ----- -------- ---------- ---------------------------------------------
--------------------------------------------------------------------------*/
void vdDisplayDataStr(char* pchInStr,int inYCord,int inClearDp,int inOption) {
    int inXCord = 1,
    inLen;

    inLen = strlen(pchInStr);

    if (inLen > 21)
        return;
    if (inYCord > 8)
        inYCord = inImamLineNumber; 
    if (inYCord < 1)
        inYCord = 1;

    switch (inOption) {
    case ML_RIGHT:
        inXCord = 21 - inLen + 1;
        break;
    case ML_LEFT:
        inXCord = 1;
    case ML_CENTER:
        inXCord = (21 - inLen) / 2;
    case ML_DEFAULT:
    default:
        break;
    }

    inMLDisplayAt(inXCord, inYCord, pchInStr, inClearDp, ML_USE_GIVEN_FONT, 0, "F:ASC8X21.VFT");
}

/*-----------------------------------------------------------------------------
* Routine Name : inDisplayCustLogo (int , int , char *, int , int , int, int)
* Description  : Displays a defined logo on the screen
* Parameters   :    inX                     X co-ordinate 
*                   inY                     Y co-ordinate 
*                   *pszLogoFontFileName    Logo File name (xxx.VFT)
*                   inWidth                 Width in the grid 
*                   inHeight                Height in the Grid
*                   inFontSize              What type of font 
*                                           CHARS_8X16, 
*                                           CHARS_4X16 or
*                                           CHARS_8X21
*                   inOffset                The offset in the VFT file where the logo starts
* Returns      : VS_SUCCESS if OK
*                In case of errors:
*                   ERR_LOGO_TOO_BIG
*                   ERR_LOGO_TOO_WIDE_FOR_GRID
*                   ERR_LOGO_TOO_TALL_FOR_GRID
*                   ERR_INVALID_LOGO_SIZE
* Notes        : Nil
*
* Modification History :
* #     Date     Who                     Description
* ----- -------- --------------------------------------------------------------

*------------------------------------------------------------------------------
*/

int inDisplayCustLogo(int inX,int inY,char* pszLogoFontFileName,int inWidth,int inHeight,int inFontSize,int inOffset) {
    int inI = 0,
    inJ = 0,
    inTLX,
    inTLY,
    inBRX,
    inBRY,
    inTotals;
    char szSavedFontName[FILENAME_SIZE + 1],
    szPixBuf[168 + 1];  // 21*8 + 1 MAX!!

    if (strlen(pszLogoFontFileName) == 0)
        return (ERR_INVALID_LOGO_NAME);
    get_font(szSavedFontName);                              // Get the current font
    wherewin(&inTLX, &inTLY, &inBRX, &inBRY);               // Save the current window coordinates
    set_font(pszLogoFontFileName);                          // set the desired font

    inTotals = inWidth * inHeight;
    switch (inFontSize) {
    case CHARS_4X8:
        if (inTotals > 32)
            return (ERR_LOGO_TOO_BIG);
        if (inWidth > 8)
            return (ERR_LOGO_TOO_WIDE_FOR_GRID);
        if (inHeight > 4)
            return (ERR_LOGO_TOO_TALL_FOR_GRID);
        break;
    case CHARS_8X16:
        if (inTotals > 64)
            return (ERR_LOGO_TOO_BIG);
        if (inWidth > 16)
            return (ERR_LOGO_TOO_WIDE_FOR_GRID);
        if (inHeight > 4)
            return (ERR_LOGO_TOO_TALL_FOR_GRID);
        break;
    case CHARS_8X21:
    default:
        if (inTotals > 168)
            return (ERR_LOGO_TOO_BIG);
        if (inWidth > 21)
            return (ERR_LOGO_TOO_WIDE_FOR_GRID);
        if (inHeight > 8)
            return (ERR_LOGO_TOO_TALL_FOR_GRID);
        break;
    }
    if (inTotals <= 0)
        return (ERR_INVALID_LOGO_SIZE);

    inJ = 0;
    for (inI = 0; inI < inTotals; inI++) {
        szPixBuf[inJ++] = (char) (inI + inOffset);  // The logo can be defined anywhere in the VFT file
    }    
    szPixBuf[inTotals] = NULL_CH;  

	gotoxy(1, 1);

    for (inI = 0; inI < inHeight; inI++) {
        write_at((szPixBuf + (inWidth * inI)), inWidth, inX, inY++);
    }

    set_font(szSavedFontName);
    window(inTLX, inTLY, inBRX, inBRY);
    return (VS_SUCCESS);
}




int MULTILNG_CODE_CHECK(char* a,char* b,short * c,char* d,unsigned char* e) {
    GET_VER(a, b, c, d, e);
    return 1;
}

#undef VSMULTILNG_C
